# Maintainer: Ryuta Suzuki <oroppas@gmail.com>

_realname=path
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=16.7.1
pkgrel=1
provides=("${MINGW_PACKAGE_PREFIX}-python3-path=${pkgver}"
          "${MINGW_PACKAGE_PREFIX}-python-path.py")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-path"
           "${MINGW_PACKAGE_PREFIX}-python-path.py")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-path"
          "${MINGW_PACKAGE_PREFIX}-python-path.py")
pkgdesc="File system based database that uses python pickles (mingw-w64)"
url="https://github.com/jaraco/path"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-python-wheel")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-flake8")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha512sums=('7d660373046845a5882a316051c350558527d6d8a5cd11735d38214f986c8e096f72b45f87cfec41bf6171e7845287a42e6e45535f87a01b46670eccd4013dbf')

prepare() {
  rm -rf python-build-${MSYSTEM}
  cp -r "path-${pkgver}" "python-build-${MSYSTEM}"
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE
}
